package cn.com.homeyoda.aimate.aihealth.ui.my.questionnaire;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.QuestionnaireBean;

public class QuestionnaireAdapter extends BaseQuickAdapter<QuestionnaireBean, BaseViewHolder> {

    public QuestionnaireAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, QuestionnaireBean item) {
        helper.setText(R.id.tv_title, item.getTitle());
        helper.setText(R.id.tv_desc, item.getDescribe());
        helper.setText(R.id.tv_date, "时间：" + item.getStartTime());

        //status  1未开始 2进行中 3已结束
        String status;
        boolean isFinished = false;
        if (item.getStatus() == 1) {
            status = "未开始";
        } else if (item.getStatus() == 2) {
            status = "进行中";
        } else {
            status = "已结束";
            isFinished = true;
        }
        helper.setText(R.id.tv_label, status);
        helper.setBackgroundRes(R.id.tv_label, isFinished ? R.drawable.shape_grey_radius_16 : R.drawable.shape_green_radius_16);

        //answer 回答题数 大于0为已回答
        boolean isAnswer = item.getAnswer() > 0;
        helper.setText(R.id.btn_join, isAnswer  ? "已参与" : "立即参与");
        helper.setGone(R.id.btn_join, !isFinished);
        if (!isFinished) {
            helper.setEnabled(R.id.btn_join, !isAnswer);
            helper.addOnClickListener(R.id.btn_join);
        }
    }

    @Override
    public void setNewData(@Nullable List<QuestionnaireBean> data) {
        super.setNewData(data);
    }
}
